﻿using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Hangfire
{
    /// <summary>
    /// Hangfire的配置,可以和配置文件绑定,节为Hangfire
    /// </summary>
    public class HangfireConfig
    {
        /// <summary>
        /// 存储类别:
/*      0:内存
      1:MS SQLServer
      2:MySQL
      3:Redis*/
        /// </summary>
        public int StorageType { get; set; } = 0;
        /// <summary>
        /// 存储的连接串
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// 工作线程数，运行中的最大任务数，默认20
        /// </summary>
        public int WorkerCount { get; set; } = 20;

        /// <summary>
        /// 控制面板用户名,用户名和密码都为空，则不控制
        /// </summary>
        public string UserName { get; set; } = string.Empty;

        /// <summary>
        /// 控制面板密码
        /// </summary>
        public string Password { get; set; } = string.Empty;

        /// <summary>
        /// 控制面板路径,默认为/job
        /// </summary>
        public string StartUpPath { get; set; } = "/job";
        
        /// <summary>
        /// 控制面板只读路径,默认为/jobread
        /// </summary>
        public string ReadOnlyPath { get; set; } = "/jobread";
        
        /// <summary>
        /// 可用的队列，可以增加，默认为default,recurring
        /// </summary>
        public string[] Queues { get; set; } = new string[] { "default", "recurring" };

        /// <summary>
        /// 循环Jobless的默认队列
        /// </summary>
        public string DefaultRecurringQueueName { get; set; } = "recurring";

        /// <summary>
        /// 存储的表名前缀，默认为Hangfire
        /// </summary>
        public string TablesPrefix { get; set; } = "Hangfire";

        /// <summary>
        /// 监控Hangfire运行情况,CPU\内存,默认为10秒一次
        /// </summary>
        public int Heartbeat { get; set; } = 10;

        IConfiguration configuration;

        public HangfireConfig()
        {

        }

        public HangfireConfig(IConfiguration configuration)
        {
            this.configuration = configuration;

            Bind(configuration);
        }

        /// <summary>
        /// 绑定配置文件
        /// </summary>
        /// <param name="configuration"></param>
        public void Bind(IConfiguration configuration)
        {
            configuration.GetSection("Hangfire").Bind(this);
        }
    }
}
